package Messages;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import ocsf.server.ConnectionToClient;
import Server.SQLConnection;

public class MessageContinueStep {
	
	private ConnectionToClient client ;
	private ArrayList<Object> str ; 
	public static String TableName;
	private ResultSet RunNewRs;
	static int row1;

	
public MessageContinueStep(ArrayList<Object> msg, ConnectionToClient client) {
		
		this.client= client ;
		this.str= msg; 		
		
	}

public void Run(String ScenarioId) throws SQLException, IOException {
	
	SQLConnection sc = new SQLConnection();
	/*
	java.sql.PreparedStatement ScenarioName = sc.getConnection().prepareStatement("SELECT * FROM hts.run b where idRun='"+ScenarioId+"';");
	ResultSet RunRs= ScenarioName.executeQuery();
	
	if (!RunRs.next())
	{		
		client.sendToClient("Error"); // if the user was not found 
		
	}
	
		else {
		
			
			if (RunRs.getString(3).equals("Run"))
			{
				client.sendToClient("StatusRun");
			}
		
			else
				{*/
				TableName= ScenarioId;//RunRs.getString(2);	
				
		
			 

			java.sql.PreparedStatement ScenarioTemp = sc.getConnection().prepareStatement("SELECT t.`idScenario`,t.`TestDescription`,t.`Status` FROM hts."+TableName+" t;");
		
		
			RunNewRs= ScenarioTemp.executeQuery();
			
			ArrayList<Object> Run =new ArrayList<Object>();
			Run.add("RunStepFirst");
			Run.add(TableName);
			Run.add("1");
			while (RunNewRs.next())
			{
				Run.add(RunNewRs.getInt(1));
				Run.add(RunNewRs.getString(2));
				Run.add(RunNewRs.getString(3));
			}
	
		
		
			

			java.sql.PreparedStatement UpdateRun = sc.getConnection().prepareStatement("UPDATE hts.Run SET Status= ?  where SName='"+TableName+"';");
			UpdateRun.setString(1, "Run");
		
			UpdateRun.executeUpdate();
			
			UpdateRun.close();
			
				
			client.sendToClient(Run);
		
				}
		
		//}


		


	}
